import json


def parse_response(response):
    """
    解析响应内容，提取活动相关信息并放入字典的函数
    :param response: requests库的Response对象
    :return: 以活动名称为键、包含活动相关时间及状态信息的字典为值的字典，如果解析出现异常则返回None
    """
    try:
        if response.status_code == 200:
            response_dict = response.json()
            result_dict = {}
            activity_list = response_dict["data"]["list"]
            for activity in activity_list:
                name = activity["name"]
                startTime = activity["startTime"]
                endTime = activity["endTime"]
                joinStartTime = activity["joinStartTime"]
                statusName = activity["statusName"]
                # 将相关信息整合到一个字典中，作为值放入result_dict
                result_dict[name] = {
                    "startTime": startTime,
                    "endTime": endTime,
                    "joinStartTime": joinStartTime,
                    "statusName": statusName
                }

            return result_dict
            print("请求体解析完成!")
    except json.JSONDecodeError as e:
        print(f"JSON解析出错: {e}")
    return None
